package com.imti.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.imti.dao.CardDao;
import com.imti.dao.PatientDao;
import com.imti.entity.PatientDot;
import com.imti.entity.Patient;
import com.imti.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (Patient)表服务实现类
 *
 * @author makejava
 * @since 2023-02-01 08:43:22
 */
@Service("patientService")
public class PatientServiceImpl extends ServiceImpl<PatientDao, Patient> implements PatientService {

    @Autowired
    private PatientDao patientDao;

    @Autowired
    private CardDao cardDao;

    @Override
    public Patient findPatByAccId(int accId) {
        return patientDao.findPatByAccId(accId);
    }

    @Override
    public int addPat(Patient patient) {
        patientDao.addPat(patient);
        String cardCode=patient.getCardCode();
        int random=(int)(Math.random()*9+1);
        Long TimeStamp=System.currentTimeMillis();
        String cardNum=(TimeStamp.toString()+random);
        cardDao.addCard(cardNum,cardCode);
        return 1;
    }

    @Override
    public List<PatientDot> getPatCardCode(String cardCode) {
        return patientDao.getPatCardCode(cardCode);
    }
}

